<?php
require_once __DIR__ . '/includes/functions.php';

if (!isset($_GET['file']) || !isset($_GET['route']) || $_GET['route'] !== 'post') {
    header('Location: /');
    exit;
}

$file = basename($_GET['file']);
$filepath = POSTS_DIR . '/' . $file;

if (!file_exists($filepath)) {
    header('HTTP/1.0 404 Not Found');
    echo '文章未找到';
    exit;
}

$content = file_get_contents($filepath);
$title = pathinfo($file, PATHINFO_FILENAME);

render_template('header', ['title' => $title]);
?>

<article>
    <?= htmlspecialchars_decode($content) ?>
</article>

<?php
render_template('footer');
?>
